package hanjia;

import java.util.LinkedList;
import java.util.Queue;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2025/2/9-上午11:49
 * Since  :   1.0
 * Version:   1.0
 */
public class LeetCode104 {

    public int maxDepth(TreeNode root) {

        if (root==null){
            return 0;
        }

        return Math.max(maxDepth(root.left),maxDepth((root.right)))+1;
    }

    public int maxDepth2(TreeNode root) {

        if (root==null){
            return 0;
        }
        Queue<TreeNode> queue=new LinkedList<>();
        queue.offer(root);
        int count=0;
        while (queue.isEmpty()){
            int size=queue.size();
            for (int i=0;i<size;i++){
                TreeNode poll = queue.poll();
                if (poll.left!=null){
                    queue.offer(poll.left);

                }
                if (poll.right != null) {
                    queue.offer(poll.right);
                }


            }
            count++;


        }
        return count;


    }
}
